// UP回到顶部
$(window).scroll(function () {
  var scroll_len = $(window).scrollTop();
  if (scroll_len > 200) {$('.QZ-up').fadeIn();} else {$('.QZ-up').fadeOut();}
});
$("body").append("<div class='QZ-up icon'></div>")
$('.QZ-up').click(function () {
  $("body,html").animate({scrollTop: 0}, 300);
});
  //阻止事件冒泡
  function stopNextEvent(evt) {
    var e = (evt) ? evt : window.event;
    if (window.event) {
        e.cancelBubble = true;// ie下阻止冒泡
    } else {
        //e.preventDefault();
        e.stopPropagation();// 其它浏览器下阻止冒泡
    }
}
  //meun
$('.header-wrap .header-top .num , .header-wrap .burger .bj').click(function (obj,evt) {
    stopNextEvent(evt);
    $(".header-wrap .header-top .num").toggleClass('active');
    $(".header-wrap .burger").stop().slideToggle(300)
    $("body").toggleClass("noscroll")
})
 
  // 切换click
$(".switchwarp-ck .switchlabe .tab").click(function() {
    $(this).addClass('on').siblings().removeClass('on');
    var i=$(this).index();
    $(this).parents(".switchwarp-ck").find(".switchbox .switchitem ").eq(i).show().siblings().hide();
    $(this).parents(".switchwarp-ck").find(".switchmore a").eq(i).show().siblings().hide();
    $(window).trigger('scroll');
})

  //首页的轮播
if ($(".swiper_lunbox .swiper .swiper-slide").size() >= 1) {
  var swiper = new Swiper('.swiper_lunbox .swiper', {
      lazy: {
        loadPrevNext: true,
      },
      loop:true,
      speed: 400,
      autoplay: {
          delay: 5000,
          disableOnInteraction: false,
      },
      pagination: {
          el: '.swiper_lunbox .swiper-pagination',
          clickable: true,
      },
  });
}
// swiper  双向控制
if($(".swipercontroller .gallerySwiper .swiper-slide").size()>=1){
  $(".swipercontroller").each(function(i){
        var view='auto';
       if($(this).attr("data-slide")){ 
          view=$(this).attr("data-slide");
        }
       $(this).addClass("swipercontroller"+i);
       var thumbsSwiper='thumbsSwiper'+i;
       var gallerySwiper='gallerySwiper'+i;
       thumbsSwiper= new Swiper(".swipercontroller"+i+" .thumbsSwiper .swiper", {
          slidesPerView: view,
          observer:true,
          observeParents:true,
          watchSlidesVisibility: true,//防止不可点击
          
        });
        gallerySwiper= new Swiper(".swipercontroller"+i+" .gallerySwiper.swiper", {
          slidesPerView: 'auto',
          thumbs: {
            swiper: thumbsSwiper,
          },
          on:{
            slideChangeTransitionStart: function (swiper, event) {
                $(window).trigger('scroll');
            },
          }
        })
  })
}
// swiperauto
if($(".swipeview .swiper-slide").size()>=1){
  $(".swipeview").each(function(i){
        var view='auto';
       if($(this).attr("data-slide")){ 
          view=$(this).attr("data-slide");
        }
       $(this).addClass("swipeview"+i);
       var swipeview='swipeview'+i;
        swipeview= new Swiper(".swipeview"+i+".swiper", {
          slidesPerView: view,
          observer:true,
          observeParents:true,
          autoHeight: true, //高度随内容变化
          lazy: {
            loadPrevNext: true,
            loadPrevNextAmount: 2,
        },
          scrollbar: {
            el: '.swipeview'+i+' .swiper-scrollbar',
          },
          on:{
            slideChangeTransitionStart: function (swiper, event) {
                $(window).trigger('scroll');
            },
          }
        })
  })
}
// 分类
if($(".swiper-tab.switchlabe .swiper-slide").size()>=1){
  var swiper_tab = new Swiper(".swiper-tab.switchlabe .swiper", {
      slidesPerView: 'auto',
      observer:true,
      observeParents:true,
    });
}
// 导航
if($(".swipernav .swiper-slide").size()>=1){
  var swipernav = new Swiper(".swipernav .swiper", {
      slidesPerView: 'auto',
    });
    $(".swipernav  .swiper-slide").each(function (index) {
      if ($(this).hasClass("on") && index>2) {
          var index_ = $(this).index();
          swipernav.slideTo(index_, false);//切换到第一个slide，速度为1秒;
      }
  })
}
// 打开筛选分类
function open_layerscreen(){
    $(".layerscreen ,.layerscreen .bj").show();
    $(".layerscreen .screenbox").removeClass("an_hide");
    $(".layerscreen .screenbox").addClass("an_show");
    $(".title .more.screen").addClass("on")
}
// 关闭筛选分类
function close_layerscreen(){
  $(".layerscreen .screenbox").removeClass("an_show");
  $(".layerscreen .screenbox").addClass("an_hide");
  $(".layerscreen .bj").stop().fadeOut(300,function(){
    $(".layerscreen ").hide();
    $(".title .more.screen").removeClass("on")
  });
}
$(".layerscreen .screenbox .scroll li a").click(function(){
  $(this).toggleClass("on")
})
// 提交筛选分类
function submit_layerscreen(){
  var arr=[]
    $(".layerscreen .screenbox .scroll li a").each(function(){
       if($(this).hasClass("on")){
        var id=$(this).attr("data-id");
         arr.push(id)
       }
    })
    console.log(arr) //获取搜索的内容字段
    close_layerscreen()//  调用搜索框
}
 
// 打开左侧导航
function openflexdnav(){
  $(".flexdnav ,.flexdnav .bj").show();
  $(".flexdnav .list").removeClass("an_hide_Right");
  $(".flexdnav .list").addClass("an_show_lef");
  
}
// 关闭左侧导航
function closeflexdnav(){
$(".flexdnav .list").removeClass("an_show_lef");
$(".flexdnav .list").addClass("an_hide_Right");
$(".flexdnav .bj").stop().fadeOut(300,function(){
  $(".flexdnav ").hide();
});
}

// 游戏截图
function scroll_img_height(){
    var box=$(".swiperimgbox .swiper .swiper-slide").eq(1).find("img");
    var imgo = new Image();
        imgo.src = box.attr('src');
        imgo.onload=function(){
          var img_h=imgo.height;
          var img_w=imgo.width;
          var slide=1.06;
          if (img_h>img_w){
            $(".swiperimgbox").addClass('swiperimg-h')
            slide=1.8;
          }
          var swiperimgbox = new Swiper(".swiperimgbox .swiper", {
            slidesPerView: slide,
            observer:true,
            observeParents:true,
            spaceBetween: 10,
            lazy: {
              loadPrevNextAmount: 3,
                loadPrevNext: true,
            },
        });
      }
  }
if($(".swiperimgbox .swiper-slide").size()>=1){
    var time_ = window.setTimeout("scroll_img_height()",500);//使用字符串执行方法;
}
  	// 放大图片
if($('.swiperimgbox ').length>0 || $('.details_html img').length>0){
  var pswpHtml = '';
  pswpHtml +='<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true"><div class="pswp__bg"></div><div class="pswp__scroll-wrap"><div class="pswp__container"><div class="pswp__item"></div><div class="pswp__item"></div><div class="pswp__item"></div></div><div class="pswp__ui pswp__ui--hidden"><div class="pswp__top-bar"><div class="pswp__counter"></div><button class="pswp__button pswp__button--close" title="Close (Esc)"></button><button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button><button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button><div class="pswp__preloader"><div class="pswp__preloader__icn"><div class="pswp__preloader__cut"><div class="pswp__preloader__donut"></div></div></div></div></div><button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button><button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button><div class="pswp__caption"><div class="pswp__caption__center"></div></div></div></div></div>'
   $("body").append(pswpHtml);
   function pswpFun(els){
      if(els.length>0){
          els.find('p > img').on('click',function(){
                  var pswpElement = document.querySelectorAll('.pswp')[0];
              var items = new Array();
              $.each(els.find('p > img'), function(i, v) {
                      $(v).attr("rel", i);
                  items.push({
                      src: $(v).attr("src"),
                      w: $(v).width(),
                      h: $(v).height()
                  });
              });
              var options = { index: parseInt($(this).attr("rel")) };
              var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
      
              if($(this).parents("a").length>0){
                     return;
                 }else{
                     gallery.init();
                 }
          });
      }
  }
  pswpFun($('.details_html '));
  if($('.swiperimgbox').length>0){
      $('.swiperimgbox').find('img').on('click',function(){
              var pswpElement = document.querySelectorAll('.pswp')[0];
          var items = new Array();
          $.each($('.swiperimgbox').find('img'), function(i, v) {
                  $(v).attr("rel", i);
              items.push({
                     src: $(v).attr("src"),
                     w: $(v).width(),
                     h: $(v).height()
              });
          });
          var options = { index: parseInt($(this).attr("rel")) };
          var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
             gallery.init();
      });
  }
  
}
 // 详情的高速下载
$(".downtop .checkbox").click(function(){
  $(this).toggleClass("checked");
  showquick()
})
function showquick(){
  if($(".downtop .checkbox").hasClass("checked")){
      $(".downtop .downbox .down.quick").show().siblings().hide();
  }else{
      $(".downtop .downbox .down.quick").hide().siblings().show();
  }
}
if($(".downtop .checkbox").size()>=1){
  showquick()
}

// 详情右侧的点赞
function give(obj_,id,type){
  if($(obj_).hasClass("active")){
    alert('您已经点赞过了,请勿重复点赞');
  }else{
      $.tipsBox({
          obj: $(obj_),
          str: "+1",
          callback: function () {
          }
      });
      $(obj_).addClass("active");
      if($(obj_).find("p").size()>=1){
        $(obj_).find("p").text(parseInt($(obj_).find("p").text())+1)
      }
      // $.ajax({
      //     url:"/api/zan",
      //     type:"POST",
      //     data:{type:type,id:id},
      //     dataType:"json",
      //     success:function (res) {
      //         if(res.code == 1){
      //             $.tipsBox({
      //                 obj: $(obj_),
      //                 str: "+1",
      //                 callback: function () {
      //                 }
      //             });
      //             $(obj_).addClass("active");
      //         }else {
      //             alert(res.message);
      //         }
      //     },
      //     error:function (e) {
      //         alert("加载失败");
      //     }
      // });
  }
 
}
//  ------点赞------
$.extend({
  tipsBox: function (options) {
    options = $.extend({
      obj: null,  //jq对象，要在那个html标签上显示
      str: "+1",  //字符串，要显示的内容;也可以传一段html，如: "<b style='font-family:Microsoft YaHei;'>+1</b>"
      startSize: "12px",  //动画开始的文字大小
      endSize: "30px",    //动画结束的文字大小
      interval: 600,  //动画时间间隔
      color: "red",    //文字颜色
      callback: function () { }    //回调函数
    }, options);
    $("body").append("<span class='numtishi'>" + options.str + "</span>");
    var box = $(".numtishi");
    var left = options.obj.offset().left + options.obj.width() / 5-10;
    var top = options.obj.offset().top - options.obj.height()/5-10;
    box.css({
      "position": "absolute",
      "left": left + "px",
      "top": top + "px",
      "z-index": 9999,
              "width":"50px",
              "text-align":"center",
      "font-size": options.startSize,
      "line-height": options.endSize,
      "color": options.color
    });
    box.animate({
      "font-size": options.endSize,
      "opacity": "0",
      "top": top - parseInt(options.endSize) + "px"
    }, options.interval, function () {
      box.remove();
      options.callback();
    });
  }
});


